import {getHome,brandDatail,cartDatail,getCartRelated,getCart,addCollect,addComment,addCart} from '../../api'

export function homeAction(){
    return  async(dispatch:Function)=>{
        let result = await getHome();
        dispatch({
            type:'INIT_HOME',
            payload:result.data
        })
    }
}
export function brandDetail(id:number){
    return  async(dispatch:Function)=>{
        let result = await brandDatail(id);
        dispatch({
            type:'INIT_BRAND',
            payload:result.data
        })
    }
}
export function cartDetail(id:number){
    return  async(dispatch:Function)=>{
        let result = await cartDatail(id);
        dispatch({
            type:'INIT_CART',
            payload:result.data
        })
    }
}
export function cartRelated(id:number){
    return  async(dispatch:Function)=>{
        let result = await getCartRelated(id);
        dispatch({
            type:'INIT_RELATED',
            payload:result.data
        })
    }
}

export function addCartAction(){
    return async(dispatch:Function)=>{
        const result = await getCart();
        dispatch({
            type:'CART_INFO',
            payload:result.data
        })
    }
}
export function addCollectAction(typeId:string,valueId:string){
    return async(dispatch:Function)=>{
        const result = await addCollect(typeId,valueId);
        dispatch({
            type:'ADD_COLLECT',
            payload:result.data
        })
    }
}
export function addToCart(goodsId:string,number:string,productId:string){
    return async(dispatch:Function)=>{
        const result = await addCart(goodsId,number,productId);
        alert((result as any).errmsg)
        // dispatch({
        //     type:'ADD_CART',
        //     payload:result.data
        // })
    }
}
export function addCommentAction(content:string,typeId:string,valueId:string){
    return async(dispatch:Function)=>{
        const result = await addComment(content,typeId,valueId);
        dispatch({
            type:'ADD_COMMENT',
            payload:result.data
        })
    }
}
